<template>
  <el-table
    v-loading="loading"
    :data="tableData"
    border
    style="width: 100%"
    @selection-change="$emit('selection-change', $event)"
  >
    <!-- 复选列 -->
    <el-table-column type="selection" width="55" align="center" />

    <!-- 常规列 -->
    <el-table-column type="index" label="序号" width="60" align="center"/>
    <el-table-column prop="name" label="探针名称" align="center" />
    <el-table-column prop="version" label="探针版本" align="center" />
    <el-table-column prop="createdTime" label="版本创建时间" width="180" align="center"/>
    <el-table-column prop="signatureStatus" label="版本状态" width="120" align="center"/>

    <!-- 操作列 -->
    <el-table-column label="操作" width="560" align="center">
      <template #default="{ row }">
        <!-- 固定操作按钮 -->
        <el-button
          v-if="['设计中', '校对未通过','审定未通过'].includes(row.signatureStatus)"
          size="mini"
          type="text"
          icon="el-icon-edit"
          @click="handleEditDesign(row)"
          v-hasPermi="['probe:version:edit']"
        >修改设计</el-button>

        <el-button
          size="mini"
          type="text"
          icon="el-icon-document"
          @click="$emit('view-draw', row)"
          v-hasPermi="['probe:version:view']"
        >查看图纸</el-button>

        <!-- 动态操作按钮 -->
        <template v-if="row.signatureStatus === '设计中'">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload"
            @click="handleSubmitVerification(row)"
            v-hasPermi="['probe:version:submit']"
          >提交校对</el-button>
        </template>
        <template v-if="row.signatureStatus === '已发布'">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-refresh"
            @click="handleVersionUpdate(row)"
            v-hasPermi="['probe:version:update']"
          >版本更改</el-button>
        </template>

        <!-- 条件显示按钮 -->
        <el-button
          v-if="row.signatureStatus === '校对未通过' || row.signatureStatus === '审定未通过'"
          size="mini"
          type="text"
          icon="el-icon-message"
          @click="$emit('view-comments', row)"
          v-hasPermi="['probe:version:comment']"
        >查看批注</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  name: 'designComponent',
  props: {
    // 表格数据（数组）
    tableData: {
      type: Array,
      required: true,
      default: () => []
    },
    // 加载状态（布尔值）
    loading: {
      type: Boolean,
      default: false
    },
    projectId: {
      type: [String, Number],
      required: true
    },
    // 其他数据（任意类型）
    extraConfig: {
      type: Object,
      default: () => ({})
    }
  },
  methods: {
    handleEditDesign(row) {
      let action = null;
      if(row.signatureStatus === '设计中') {
        action = 'nowVersion'
      }else{
        action = 'modify'
      }
      // 调用API更新设计
      this.$emit('edit-design',row,action) // 通知父组件刷新
    },
    handleSubmitVerification(row) {
      console.log('design',this.tableData)
      console.log('submit-nextStage', row)
      const note = "submitToVerify"
      this.$emit('submit-nextStage',row,note)
    },
    handleVersionUpdate(row) {
      const action = 'newVersion'
      // 版本更新逻辑
      console.log('版本更改',row);
      this.$emit('update-version', row,action);
    }
  }
};
</script>
